String.prototype.endWith = function (endStr) {
    var d = this.length - endStr.length;
    return (d >= 0 && this.lastIndexOf(endStr) == d)
};

var str = "abcdef cefc";
console.log(str.endWith("ef"));


// a b c d e f 6
// e f     2
// this.lastIndexOf(endStr) 4